<!DOCTYPE html>
<html lang="zh">
    <head>
        <title>${content.title} - ${category.name}</title>
        <meta name="keywords" content="<#list getKeywords(content.title) as a>${a}<#sep>,</#list>"/>
        <meta name="description" content="${content.description!}"/>
        <@tools.includePlace path="/common/8ddab9ba-a8aa-4745-86c6-66bf1c2c976c.html"/> <#-- header -->
        <link href="${site.sitePath}assets/swiper/swiper.min.css" rel="stylesheet"/>
    </head>
    <body>
        <@tools.includePlace path="/common/c32a4f4a-ff5d-49cf-bb59-5d9784539174.html"/> <#-- 导航 -->
        <div class="banner-l3 position-relative d-flex align-items-center justify-content-center" style="background:#22407c url(${site.sitePath}assets/img/banner-l3-bg-1.png) 50% 50% no-repeat;">
            <div class="container text-center position-relative py-3 py-md-4 text-white">
                <div class="breadcrumbs fs-7 text-white d-inline-flex align-items-center text-opacity-50" data-diy="category" data-diy-id="${category.id}">
                    <@include path="/ftl/bread.ftl"/><#-- 面包屑导航 -->
                </div>
                <h1 class="my-4" data-diy="content" data-diy-id="${content.id}"><a href="${url!}" class="text-white">${content.title}</a></h1>
            </div>
        </div>
        <div class="container">
			<#if content.hasProducts>
            <div class="row my-4" data-diy="content" data-diy-id="${content.id}">
				<@cms.contentProductList contentId=content.id orderType='asc'>
                <div class="col-md-5">
                        <div class="product-gallery swiper-container mb-3">
                            <div class="swiper-wrapper">
                                <#if content.cover?has_content>
                                <div class="swiper-slide"><img src="${content.cover!}" alt="${content.title}"></div>
                                </#if>
                                <#list page.list as product>
                                <#if product.cover?has_content><div class="swiper-slide"><img src="${product.cover!}" alt="${product.title}"></div></#if>
                                </#list>
                            </div>
                        </div>
                        <div class="thumb-list swiper-container mb-3">
                            <div class="swiper-wrapper">
                                <#if content.cover?has_content>
                                <div class="swiper-slide"><a href="javascript:void(0);"><img  src="${content.cover!}" alt="${content.title}"></a></div>
                                </#if>
                                <#list page.list as product>
                                <#if product.cover?has_content>
                                <div class="swiper-slide" data-id="${product.id!}"><a href="javascript:void(0);"><img  src="${product.cover!}" alt="${product.title}"></a></div>
                                </#if>
                                </#list>
                            </div>
                        </div>
                </div>
                <div class="col-md-7">
                    <header>
                        <h1><a href="${url!}">${content.title}</a></h1>
                        <p class="fs-1"><label>价格</label> <span class="price text-danger"></span></p>
                        <p><label>库存</label> <span class="inventory"></span></p>
                    </header>
                    <form action="${site.dynamicPath}member/order.html">
                        <p>
                            <#list page.list as product>
								<label class="pe-4"><input type="radio" name="productId" value="${product.id}"/>${product.title}</label>
							</#list>
                        </p>
                        <p><label>数量</label><input type="number" name="quantity" value="1" min="1" size="4"/></p>
                        <input type="submit" class="btn btn-primary" value="立刻购买"/>
                    </form>
                </div>
                </@cms.contentProductList>
            </div>
            </#if>
            <div class="row">
                <aside class="col-md-3">
                    <h3 class="circle">相关推荐</h3>
                    <div>
                        <#if content.tagIds?has_content>
                        <@cms.search tagId=content.tagIds modelId=content.modelId pageSize=10>
                            <#list page.list as a>
                                <#if a.cover?has_content>
                                    <p><a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url}</#if>" title="${a.title}"><img class="w-100" src="${a.cover!}" alt="${a.title!}"/></a></p>
                                </#if>
                                <p><a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url}</#if>" title="${a.title}">${a.title}</a></p>
                            </#list>
                            </@cms.search>
                        <#else>
                        <@cms.contentList categoryId=content.categoryId modelId=content.modelId pageSize=10>
                            <#list page.list as a>
                                <#if a.cover?has_content>
                                    <p><a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url}</#if>" title="${a.title}"><img class="w-100" src="${a.cover!}" alt="${a.title!}"/></a></p>
                                </#if>
                                <p><a href="<#if a.onlyUrl>${site.dynamicPath}content/redirect?id=${a.id}<#else>${a.url}</#if>" title="${a.title}">${a.title}</a></p>
                            </#list>
                        </@cms.contentList>
                        </#if>
                    </div>
                </aside>
                <div class="col-md-9">
                    <ul class="nav nav-tabs" role="tablist">
                        <li class="nav-item"><a class="nav-link active" href="#content" data-bs-toggle="tab">产品详情</a></li>
                        <li class="nav-item"><a class="nav-link" href="#comment" data-bs-toggle="tab">评论(${(content.comments)!})</a></li>
                    </ul>
                    <div class="tab-content">
                        <article class="tab-pane fade clearfix  show active" id="content" data-diy="content" data-diy-id="${content.id}">
                            ${text?no_esc!}
                        </article>
                        <div class="tab-pane fade py-4" id="comment">
                            <@include path="/ftl/comment.ftl"/><#-- 评论 -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            var itemString="itemType=content&itemId=${content.id}";
        	var templatePath='${.current_template_name?keep_after('/')}';
		</script>
        <@tools.includePlace path="/footer/7f8bacb5-30ca-4641-b66f-987d447b1a85.html"/> <#-- footer -->
        <script src="${site.sitePath!}assets/ueditor/ueditor.parse.min.js"></script>
        <script src="${site.sitePath!}assets/swiper/swiper.min.js"></script>
        <script>
            var thumbSwiper = new Swiper('.thumb-list', {
                spaceBetween: 10,
                slidesPerView: 5,
                freeMode: true,
                watchSlidesVisibility: true,
                watchSlidesProgress: true,
            });
            var gallerySwiper = new Swiper('.product-gallery', {
                mousewheel: true,
                effect: 'coverflow',
                speed: 300,
                thumbs: {
                    swiper: thumbSwiper,
                }
            });
            $('input[name=productId]').change(function(){
                var selectedProductId=this.value;
                if(selectedProductId){
                    $.getJSON('${site.dynamicPath}api/directive/contentProduct?id='+selectedProductId, function(data){
                        if($('input[name=productId]:checked').val() == selectedProductId){
							$({ counter: parseInt($('.price').text()) }).animate({ counter: data.object.price }, {
								speed: 2000,
								easing: 'swing',
								step: function (now) {
								  $('.price').text(Math.ceil(now));
								}
							  });
							if(data.object.inventory>5){
								 $('.inventory').text('充足');
							}else{
								 $('.inventory').text('低');
							}
                            if(data.object.minQuantity){
                                $('input[name=quantity]').attr('min', data.object.minQuantity);
                                if(parseInt($('input[name=quantity]').val()) < data.object.minQuantity){
                                    $('input[name=quantity]').val(data.object.minQuantity);
                                }
                            }
                            if(data.object.maxQuantity && data.object.maxQuantity<data.object.inventory){
                                $('input[name=quantity]').attr('max', data.object.maxQuantity);
                            }else{
                                $('input[name=quantity]').attr('max', data.object.inventory);
                            }
                            if(parseInt($('input[name=quantity]').val()) > parseInt($('input[name=quantity]').attr('max'))){
                                $('input[name=quantity]').val($('input[name=quantity]').attr('max'));
                            }
                        }
                    });
                    var index= $('.thumb-list .swiper-slide[data-id='+selectedProductId+']').index();
                    if(0<=index){
                        gallerySwiper.slideTo(index);
                    }
                }
            });
			$('input[name=productId]').eq(0).click();
            $.getJSON('${site.dynamicPath}api/contentClick?id=${content.id}', function(data){});
            uParse('#content',{rootPath: '${site.sitePath!}assets/ueditor/'});
        </script>
    </body>
</html>
